package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;

import com.aijk.ehm.dao.mybatis.SemWeightMapper;
import com.aijk.ehm.model.SemWeight;
import com.aijk.ehm.model.SemWeightExample;
import com.aijk.ehm.model.qo.SemWeightQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 体重
 */
@Service
public class SemWeightService {
    private static Logger logger = LoggerFactory.getLogger(SemWeightService.class);

    @Autowired
    private SemWeightMapper mapper;

    public SemWeightExample getExample(SemWeightQo qo) {
        SemWeightExample example = new SemWeightExample();
        SemWeightExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (qo.getResidentId()!= null) criteria.andResidentIdEqualTo(qo.getResidentId());
            if (qo.getUid()!= null) criteria.andUidEqualTo(qo.getUid());
            if (qo.getIdcard()!= null) criteria.andIdcardEqualTo(qo.getIdcard());
            if (qo.getDevicesn()!= null && qo.getDevicesn()!="") criteria.andDevicesnEqualTo(qo.getDevicesn());

        }
        return example;
    }

    public int count(SemWeightQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(SemWeight bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(SemWeight bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public SemWeight findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<SemWeight> find(SemWeightQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<SemWeight> page(PagingRequest pagingRequest, SemWeightQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<SemWeight>(mapper.selectByExample(getExample(qo)));
    }
}